package org.coderjonny.trace;

import org.coderjonny.thread.ThreadLocalUtil;
import org.springframework.util.StringUtils;

import java.util.UUID;

public class TraceIdUtil {

    public static final String TRACE_ID = "traceId";
    public static final String SLEUTH_TRACE_NAME = "X-B3-TraceId";
    public static String newTraceId(){
        return UUID.randomUUID().toString();
    }

    public static String getNowTraceId(){
        String traceId = (String) ThreadLocalUtil.get(TRACE_ID);
        if (!StringUtils.hasText(traceId)){
            traceId = TraceIdUtil.newTraceId();
        }
        return traceId;
    }
}
